package DB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import com.mysql.jdbc.PreparedStatement;

public class Request extends DB{
	private static Request singleton = new Request();
	private static Statement statement;
	private static PreparedStatement prepareStatement;
	private static ResultSet resultSet;
	
	public static Request getInstance(){
		return singleton;
	}
	
	public void executeUpdate(String query){
		try {
			statement = connection.createStatement();
			statement.executeUpdate(query);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void executeUpdate(String query, List<Object> list){
		try {
			prepareStatement = (PreparedStatement) connection.prepareStatement(query);
			Integer compteur = new Integer(1);
			for(Object obj : list){
				prepareStatement.setObject(compteur, obj);
				compteur = compteur + 1;
			}
			prepareStatement.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public ResultSet executeQuery(String query){
		try {
			statement = connection.createStatement();
			resultSet = statement.executeQuery(query);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return resultSet;
	}
}
